//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.crazy.plugins.gen;

import cn.org.rapid_framework.generator.GeneratorFacade;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * @className DelFilesByTableMojo
 * @description 代码生成器插件的主要goal
 * @author zhouzhendong
 * @date 2019/7/30 17:18
 * @version V1.0
 */
@Mojo(name = "del")
public class DelFilesByTableMojo extends AbstarctGeneratorMojo {
    @Parameter(property = "tableParameter",defaultValue = "${table}")
    public String tableParameter;
    @Parameter(property = "template")
    public String template;
    private GeneratorFacade g;

    public DelFilesByTableMojo() {
    }

    public void execute() throws MojoExecutionException, MojoFailureException {
        Thread currentThread = Thread.currentThread();
        ClassLoader oldClassLoader = currentThread.getContextClassLoader();

        try {
            currentThread.setContextClassLoader(this.getClassLoader());
            System.out.println("current project to build: " + this.getProject().getName());
            this.g = new GeneratorFacade();
            this.g.getGenerator().setTemplateRootDirs(new String[]{"classpath:"+ this.template});
            this.delByTable(this.parseStringArray(this.tableParameter));
        } finally {
            currentThread.setContextClassLoader(oldClassLoader);
        }

    }

    public void delByTable(String... table) {
        try {
            this.g.deleteByTable(table);
            MojoUtil.openFileIfOnWindows();
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }
}
